﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Weibo4Sharp.Model;
using System.Text;

namespace Weibo4SharpWeb.Extension
{
    public static class HtmlExtension
    {
        public static IHtmlString WeiboPic(this HtmlHelper self, WeiboStatus weibo)
        {
            if (string.IsNullOrEmpty(weibo.ThumbnailPic))
            {
                return self.Raw(string.Empty);
            }

            var sb = new StringBuilder();

            sb.AppendFormat("<div class=\"weibo-pic\">");
            sb.AppendFormat("<a href=\"{0}\" target=\"_blank\">", weibo.OriginalPic);
            sb.AppendFormat("<img src=\"{0}\" />", weibo.ThumbnailPic);
            sb.AppendFormat("</a>");
            sb.AppendFormat("</div>");

            return self.Raw(sb.ToString());
        }

        public static IHtmlString ParseEmotion(this HtmlHelper self, string content)
        {
            foreach (var em in Platform.Emotions)
            {
                content = content.Replace(em.Phrase, string.Format("<img src=\"{0}\" />", em.Url));
            }

            return self.Raw(content);
        }
    }
}